home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 1.4 KB | 64 lines | [TEXT/ttxt] |
- --<<<
- -- Kaleida Labs, Inc.
- -- Field Guide to the ScriptX Language
- -- chapter 4, example 3
-
- -- create a module to avoid naming conflicts
- module Scratch15 uses ScriptX end
- in module Scratch15
-
- -- declare globals and make sure they aren't defined already
- global i, j, k, x
-
- -- for loop examples
- for 9 do print "hello"
-
- global allSpaces := #()
- for 52 do append allSpaces ""
-
- global theMin := 100
- for i := #(1, 435, 234, 23, 8) do
- if i < theMin do theMin := i
- theMin
-
- -- examples with ranges
- for i := 1 to 23 do print i
- for i in 0 to 100 by 10 do print (i * i)
-
- -- decreasing ranges
- for i := 10 to 1 do print (i + i)
-
- -- collections as sources of iteration
- for i in #(1,2,3,4) do print i
- for i := #("Francois","Inez","Louis","Margot") do
- format debug "%* did it!\n" i @unadorned
-
- global countdown := 10 to 1
- for i in countdown do
- (format debug "%* seconds to blast off!\n" i @normal)
-
- -- multiple sources of iteration
- for 14, i := 1 to 1000 by 23 do
- (prin i @normal debug; prin " " @unadorned debug)
-
- for 14, i := 1 to 1000 by 230 do
- (prin i @normal debug; prin " " @unadorned debug)
-
- for i := 1 to 10, j := 1 to 10 by 2 do
- (
- format debug "I is %1. J is %2\n" #(i, j) #(@normal,@normal)
- print (i * j)
- )
-
- global x := 1
- for 23 while x <= 5 do (
- print x
- x := x + 1
- )
-
- for j := 1 to 100, k := 1 to 100 by 5 while j * k * k < 10000 do (
- prin j @normal debug; prin ", " @unadorned debug
- prinln k @normal debug
- )
- -->>>
-